
from typing import List
class Solution:
    # 方法一：哈希表
    def longestConsecutive(self, nums: List[int]) -> int:
        lit = []
        if len(nums)==0:
            return 0
        nums = set(nums)
        nums = list(nums)
        nums.sort()
        lit.append(nums[0])
        ans_max = 1
        for i in range(1, len(nums) ):
            if nums[i] == nums[i - 1] + 1:
                lit.append(nums[i])
            else:
                lit.clear()
                lit.append(nums[i])
            ans_max = max(ans_max, len(lit))
        return ans_max
        '''
        时间复杂度：O(N)
        空间复杂度: O(N)
        '''


# print(Solution().longestConsecutive([100, 4, 200, 1, 3, 2]))
nums = [0,3,7,2,5,8,4,6,0,1]
# nums = [0]
# nums = [1,0,1,2]
# nums = set(nums)
# nums = list(nums)
# print(nums)
print(Solution().longestConsecutive(nums))



